home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15115 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  40 lines

  1. Newsgroups: comp.lang.c
  2. Path: lugb.latrobe.edu.au!latcs1!woelkerl
  3. From: woelkerl@lion.cs.latrobe.edu.au (Eric Woelkerling)
  4. Subject: Pointer to Functions and Calls thereof??
  5. X-Nntp-Posting-Host: lion.cs.latrobe.edu.au
  6. Message-ID: <Dq01Ft.Dqn@latcs1.lat.oz.au>
  7. Sender: news@latcs1.lat.oz.au (news)
  8. Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia
  9. X-Newsreader: TIN [version 1.2 PL2]
  10. Date: Wed, 17 Apr 1996 09:09:28 GMT
  11.  
  12.     Hi!    Can anybody fill me in as to how to get a pointer to a function
  13. and then use this to do the call??  I have a situation where a particular function
  14. will be selected from a set of functions and used throughout my entire code,
  15. but the function selected will depend on the runtime selection by thge user..
  16.  
  17. so far.. I have got as far as..
  18.  
  19.  
  20.     void    func1(void){naughty bits}
  21.     void    func2(void){naughty bits}
  22.  
  23.     void    main(void)
  24.     {    void    *a[1];
  25.  
  26.         a[1]=func1;
  27.         a[2]=func2;
  28.  
  29.         (*a[1])();
  30.     }
  31.  
  32.     Is there something obvious I am missing here??  I am on a PC and using 
  33. borland c++ compiler... 
  34.  
  35.     If you can help,  please mail me directly     Thanks!
  36.  
  37.     Eric Woelkerling
  38.     woelkerl@lion.lat.oz.au
  39.  
  40.